<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>作用域插槽</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="root">
        <child>
            <!-- 构建作用域插槽，props用于接收子组件item传过来的值 -->
            <template slot-scope="props">
                <li>{{props.itemScope}}</li>
            </template>
        </child>
    </div>
    <script>
        Vue.component('child', {
            data: function(){
                return {
                    list: [1, 2, 3, 4]
                }
            },
            // :itemScope = item是子组件向作用域插槽传值,item是子组件存放list循环的值
            template: `<ul>
                            <slot v-for="item of list" :itemScope=item>{{item}}</slot>
                       </ul>`
        });
        var vm = new Vue({
            el: "#root",
        });
    </script>
</body>
</html>